From: Ian Jackson Date: Mon, 24 Feb 2014 15:16:19 +0000 (+0000) Subject: tools/console: reset tty when xenconsole fails X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~5387 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=111931f36885874103d65685ab15ea3d25d93da7;p=xen.git tools/console: reset tty when xenconsole fails If xenconsole (the client program) fails, it calls err. This would previously neglect to reset the user's terminal to sanity. Use atexit to do so. This routinely happens in Xen 4.4 RC5 with pygrub because libxl writes the value "" to the tty xenstore key when using xenconsole. After this patch this just results in a harmless error message. Reported-by: M A Young Signed-off-by: Ian Jackson CC: M A Young CC: Ian Campbell Acked-by: George Dunlap Acked-by: Ian Campbell --- v2: Fix whitespace error (reintroduce hard tab) Fix commit message not to claim ignorance about root cause --- diff --git a/tools/console/client/main.c b/tools/console/client/main.c index eb6a1a9315..7ce4f24aba 100644 --- a/tools/console/client/main.c +++ b/tools/console/client/main.c @@ -257,6 +257,13 @@ typedef enum { CONSOLE_SERIAL, } console_type; +static struct termios stdin_old_attr; + +static void restore_term_stdin(void) +{ + restore_term(STDIN_FILENO, &stdin_old_attr); +} + int main(int argc, char **argv) { struct termios attr; @@ -383,9 +390,9 @@ int main(int argc, char **argv) } init_term(spty, &attr); - init_term(STDIN_FILENO, &attr); + init_term(STDIN_FILENO, &stdin_old_attr); + atexit(restore_term_stdin); /* if this fails, oh dear */ console_loop(spty, xs, path); - restore_term(STDIN_FILENO, &attr); free(path); free(dom_path);